package com.item.service;

import com.item.dao.SchoolMapper;
import com.item.dao.model.CartKey;
import com.item.dao.model.School;
import com.item.dao.model.SchoolExample;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SchoolService {
    @Autowired
    private SchoolMapper schoolMapper;

    private static final Logger logger = Logger.getLogger(SchoolService.class);

    public int countByExample(SchoolExample example) {
        return this.schoolMapper.countByExample(example);
    }

    public School selectByPrimaryKey(String id) {
        return this.schoolMapper.selectByPrimaryKey(id);
    }

    public List<School> selectByExample(SchoolExample example) {
        return this.schoolMapper.selectByExample(example);
    }

    public int deleteByPrimaryKey(String id) {
        return this.schoolMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(School record) {
        return this.schoolMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(School record) {
        return this.schoolMapper.updateByPrimaryKey(record);
    }

    public int deleteByExample(SchoolExample example) {
        return this.schoolMapper.deleteByExample(example);
    }

    public int updateByExampleSelective(School record, SchoolExample example) {
        return this.schoolMapper.updateByExampleSelective(record, example);
    }

    public int updateByExample(School record, SchoolExample example) {
        return this.schoolMapper.updateByExample(record, example);
    }

    public int insert(School record) {
        return this.schoolMapper.insert(record);
    }

    public int insertSelective(School record) {
        return this.schoolMapper.insertSelective(record);
    }
    
    public String getLeastCode() {
    	String res = "S";
    	SchoolExample example = new SchoolExample();
    	example.setOrderByClause("code ASC");
    	List<School> list = this.schoolMapper.selectByExample(example);
    	int i = 0;
    	for(int len = list.size(); i < 100 && i < len; i++) {
    		School s = list.get(i);
    		int sCodeInt = Integer.parseInt(s.getCode().substring(1));
    		if(i < sCodeInt) {
    			break;
    		}
    	}
    	if(i == 0)
    		res += "01";
    	else
    		res += i < 10 ? "0" + i : i + "";
    	
    	return res;
    }
}